<template>
  <a-card :bordered="false">
    <!-- table区域-begin -->
    <div>
      <a-tabs v-model="activeKey" @change="handleChangeTab">
        <a-tab-pane key="0" tab="生产过程确认">
          <!-- 查询区域 -->
          <div class="table-page-search-wrapper">
            <a-form layout="inline" @keyup.enter.native="searchQuery">
              <a-row :gutter="24">
                <a-col :xl="6" :lg="7" :md="8" :sm="24">
                  <a-form-item label="生产车间">
                    <j-search-select-tag
                      type="list"
                      v-model="queryParamConfirmation.workshopCode"
                      :dictOptions="dictOptions"
                      placeholder="请选择所属车间"
                    />
                  </a-form-item>
                </a-col>
                <a-col :xl="10" :lg="11" :md="12" :sm="24">
                  <a-form-item label="制单日期">
                    <j-date
                      placeholder="请选择开始日期"
                      class="query-group-cust"
                      v-model="queryParamConfirmation.createTime_begin"
                    ></j-date>
                    <span class="query-group-split-cust"></span>
                    <j-date
                      placeholder="请选择结束日期"
                      class="query-group-cust"
                      v-model="queryParamConfirmation.createTime_end"
                    ></j-date>
                  </a-form-item>
                </a-col>
                <a-col :xl="6" :lg="7" :md="8" :sm="24">
                  <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
                    <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
                    <!-- <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button> -->
                  </span>
                </a-col>
              </a-row>
            </a-form>
          </div>
          <!-- 查询区域-END -->
          <!-- 操作按钮区域 -->
          <div class="table-operator">
            <a-button @click="handleAdd" type="primary" icon="plus">添加</a-button>
          </div>
          <div class="ant-alert ant-alert-info" style="margin-bottom: 16px">
            <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择
            <a style="font-weight: 600">{{ selectedRowKeys.length }}</a
            >项
            <a style="margin-left: 24px" @click="onClearSelected">清空</a>
            <span style="float: right">
              <a-popover title="自定义列" trigger="click" placement="leftBottom">
                <template slot="content">
                  <a-checkbox-group
                    @change="onColSettingsChange"
                    v-model="settingColumns"
                    :defaultValue="settingColumns"
                  >
                    <a-row style="width: 400px">
                      <template v-for="(item, index) in defColumns">
                        <template v-if="item.key !== 'rowIndex' && item.dataIndex !== 'action'">
                          <a-col :span="12"
                            ><a-checkbox :value="item.dataIndex"
                              ><j-ellipsis :value="item.title" :length="10"></j-ellipsis></a-checkbox
                          ></a-col>
                        </template>
                      </template>
                    </a-row>
                  </a-checkbox-group>
                </template>
                <a><a-icon type="setting" />设置</a>
              </a-popover>
            </span>
          </div>
          <a-table
            ref="confirmationTable"
            size="middle"
            :scroll="{ x: true }"
            bordered
            rowKey="id"
            :columns="confirmationColumns"
            :dataSource="confirmationTable.dataSource"
            :pagination="confirmationTable.ipagination"
            :loading="confirmationTable.loading"
            :rowSelection="{
              selectedRowKeys: confirmationSelectedRowKeys,
              onChange: onSelectChangeConfirmation,
              type: 'radio',
            }"
            :customRow="rowSelectConfirmation"
            class="j-table-force-nowrap1"
            @change="handleTableChange"
          >
            <template slot="htmlSlot" slot-scope="text">
              <div v-html="text"></div>
            </template>
            <template slot="imgSlot" slot-scope="text, record">
              <span v-if="!text" style="font-size: 12px; font-style: italic">无图片</span>
              <img
                v-else
                :src="getImgView(text)"
                :preview="record.id"
                height="25px"
                alt=""
                style="max-width: 80px; font-size: 12px; font-style: italic"
              />
            </template>
            <template slot="fileSlot" slot-scope="text">
              <span v-if="!text" style="font-size: 12px; font-style: italic">无文件</span>
              <a-button v-else :ghost="true" type="primary" icon="download" size="small" @click="downloadFile(text)">
                下载
              </a-button>
            </template>
          </a-table>
        </a-tab-pane>
        <a-tab-pane key="1" tab="确认记录">
          <!-- 查询区域 -->
          <div class="table-page-search-wrapper">
            <a-form layout="inline" @keyup.enter.native="searchQuery">
              <a-row :gutter="24">
                <a-col :xl="6" :lg="7" :md="8" :sm="24">
                  <a-form-item label="生产车间">
                    <j-search-select-tag
                      type="list"
                      v-model="queryParamRecord.workshopCode"
                      :dictOptions="dictOptions"
                      placeholder="请选择所属车间"
                    />
                  </a-form-item>
                </a-col>
                <a-col :xl="10" :lg="11" :md="12" :sm="24">
                  <a-form-item label="核查日期">
                    <j-date
                      placeholder="请选择开始日期"
                      class="query-group-cust"
                      v-model="queryParamRecord.createTime_begin"
                    ></j-date>
                    <span class="query-group-split-cust"></span>
                    <j-date
                      placeholder="请选择结束日期"
                      class="query-group-cust"
                      v-model="queryParamRecord.createTime_end"
                    ></j-date>
                  </a-form-item>
                </a-col>
                <a-col :xl="6" :lg="7" :md="8" :sm="24">
                  <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
                    <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
                    <!-- <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button> -->
                  </span>
                </a-col>
              </a-row>
            </a-form>
          </div>
          <div class="ant-alert ant-alert-info" style="margin-bottom: 16px">
            <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择
            <a style="font-weight: 600">{{ selectedRowKeys.length }}</a
            >项
            <a style="margin-left: 24px" @click="onClearSelected">清空</a>
            <span style="float: right">
              <a-popover title="自定义列" trigger="click" placement="leftBottom">
                <template slot="content">
                  <a-checkbox-group
                    @change="onColSettingsChange"
                    v-model="settingColumns"
                    :defaultValue="settingColumns"
                  >
                    <a-row style="width: 400px">
                      <template v-for="(item, index) in defColumns">
                        <template v-if="item.key !== 'rowIndex' && item.dataIndex !== 'action'">
                          <a-col :span="12"
                            ><a-checkbox :value="item.dataIndex"
                              ><j-ellipsis :value="item.title" :length="10"></j-ellipsis></a-checkbox
                          ></a-col>
                        </template>
                      </template>
                    </a-row>
                  </a-checkbox-group>
                </template>
                <a><a-icon type="setting" />设置</a>
              </a-popover>
            </span>
          </div>
          <!-- 查询区域-END -->
          <!-- 操作按钮区域 -->
          <!-- <div class="table-operator">
            <a-button @click="handleWithdraw" type="danger" v-show="activeKey === '1'" icon="minus">撤回</a-button>
          </div> -->
          <a-table
            ref="recordTable"
            size="middle"
            :scroll="{ x: true }"
            bordered
            rowKey="id"
            :columns="columns"
            :dataSource="recordTable.dataSource"
            :pagination="recordTable.ipagination"
            :loading="recordTable.loading"
            :customRow="rowSelectRecord"
            class="j-table-force-nowrap1"
            @change="handleTableChange"
          >
            <template slot="htmlSlot" slot-scope="text">
              <div v-html="text"></div>
            </template>
            <template slot="imgSlot" slot-scope="text, record">
              <span v-if="!text" style="font-size: 12px; font-style: italic">无图片</span>
              <img
                v-else
                :src="getImgView(text)"
                :preview="record.id"
                height="25px"
                alt=""
                style="max-width: 80px; font-size: 12px; font-style: italic"
              />
            </template>
            <template slot="fileSlot" slot-scope="text">
              <span v-if="!text" style="font-size: 12px; font-style: italic">无文件</span>
              <a-button v-else :ghost="true" type="primary" icon="download" size="small" @click="downloadFile(text)">
                下载
              </a-button>
            </template>

            <span slot="action" slot-scope="text, record">
              <a @click="handleDetail(record)">详情</a>
              <a-divider type="vertical" />
              <a @click="handleWithdraw(record)">撤回</a>
            </span>
          </a-table>
        </a-tab-pane>
      </a-tabs>
    </div>
    <j-vxe-table
      keep-source
      :ref="refKeys[3]"
      :loading="detailTable.loading"
      :columns="detailTable.columns"
      :dataSource="detailTable.dataSource"
      :maxHeight="300"
      :rowNumber="true"
      :rowSelection="false"
      :toolbar="false"
    />
    <erp-production-process-confirmation-before-modal
      ref="modalForm"
      @ok="modalFormOk"
    ></erp-production-process-confirmation-before-modal>
  </a-card>
</template>

<script>
import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import ErpProductionProcessConfirmationBeforeModal from './modules/ErpProductionProcessConfirmationBeforeModal.vue'
import { filterMultiDictText } from '@/components/dict/JDictSelectUtil'
import { getAction } from '@/api/manage'
import { JVxeTableModelMixin } from '@/mixins/JVxeTableModelMixin.js'
import { JVXETypes } from '@/components/jeecg/JVxeTable'
import dayjs from 'dayjs'
import { getDate } from '../../../../utils'

export default {
  name: 'ErpProductionProcessConfirmationBeforeList',
  mixins: [JeecgListMixin, mixinDevice],
  components: {
    ErpProductionProcessConfirmationBeforeModal,
  },
  data() {
    return {
      refKeys: ['unDetail', 'noMakeDetail', 'tempSaveDetail', 'approvedDetail'],
      description: '生产过程确认（前配）管理页面',
      // 生产过程确认表头
      confirmationColumns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function (t, r, index) {
            return parseInt(index) + 1
          },
        },
        {
          title: '计划单号',
          align: 'center',
          dataIndex: 'code',
        },
        {
          title: '生产车间',
          align: 'center',
          dataIndex: 'workshopCode_dictText',
        },
        {
          title: '执行日期',
          align: 'center',
          dataIndex: 'workTime',
        },
        {
          title: '制单人',
          align: 'center',
          dataIndex: 'createBy_dictText',
        },
        {
          title: '制单部门',
          align: 'center',
          dataIndex: 'sysOrgCode_dictText',
        },
        {
          title: '制单日期',
          align: 'center',
          dataIndex: 'createTime',
          customRender: function (text) {
            return !text ? '' : dayjs(text).format('YYYY-MM-DD')
          },
        },
        {
          title: '是否变更计划',
          align: 'center',
          dataIndex: 'isUpdate_dictText',
        },
        {
          title: '生产过程确认',
          align: 'center',
          dataIndex: 'recordTimes',
        },
      ],
      // 确认记录表头
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function (t, r, index) {
            return parseInt(index) + 1
          },
        },
        {
          title: '确认记录单号',
          align: 'center',
          dataIndex: 'confirmCode',
        },
        {
          title: '计划单号',
          align: 'center',
          dataIndex: 'planCode',
        },
        {
          title: '生产车间',
          align: 'center',
          dataIndex: 'workshopCode_dictText',
        },
        {
          title: '生产班组',
          align: 'center',
          dataIndex: 'team_dictText',
        },
        {
          title: '核查人',
          align: 'center',
          dataIndex: 'createBy_dictText',
        },
        {
          title: '核查部门',
          align: 'center',
          dataIndex: 'sysOrgCode_dictText',
        },
        {
          title: '核查时间',
          align: 'center',
          dataIndex: 'createTime',
          customRender: function (text) {
            return !text ? '' : dayjs(text).format('YYYY-MM-DD')
          },
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          fixed: 'right',
          width: 147,
          scopedSlots: { customRender: 'action' },
        },
      ],
      url: {
        //默认前配
        list: '/productionconfirmationbefore/erpProductionProcessConfirmationBefore/list',
        //根据路由选择前配或者后配
        beforeList: '/productionconfirmationbefore/erpProductionProcessConfirmationBefore/list',
        afterList: '/productionconfirmationafter/erpProductionProcessConfirmationAfter/list',
        delete: '/productionconfirmationbefore/erpProductionProcessConfirmationBefore/delete',
        deleteBatch: '/productionconfirmationbefore/erpProductionProcessConfirmationBefore/deleteBatch',
        exportXlsUrl: '/productionconfirmationbefore/erpProductionProcessConfirmationBefore/exportXls',
        importExcelUrl: 'productionconfirmationbefore/erpProductionProcessConfirmationBefore/importExcel',
        beforeWithdrawRecord: '/productionconfirmationbefore/erpProductionProcessConfirmationBefore/withdrawRecord',
        afterWithdrawRecord: '/productionconfirmationafter/erpProductionProcessConfirmationAfter/withdrawRecord',
        //生产过程确认列表
        planBeforeList: '/productionconfirmationbefore/erpProductionProcessConfirmationBefore/workshopPlanList',
        planAfterList: '/productionconfirmationafter/erpProductionProcessConfirmationAfter/workshopPlanList',
        //计划明细
        tslProWorkshopPlanDetail:
          '/productionconfirmationbefore/erpProductionProcessConfirmationBefore/queryDetailListByPlanId',
      },
      superFieldList: [],
      activeKey: '0',
      // 选择的生产过程
      confirmationSelectionRows: [],
      confirmationSelectedRowKeys: [],
      selectedRowKeys: [],
      //查询条件
      queryParamConfirmation: {
        createTime_begin: '',
        createTime_end: '',
        workshopCode: null,
      },
      queryParamRecord: {
        createTime_begin: '',
        createTime_end: '',
        workshopCode: null,
      },
      //生产过程列表数据
      confirmationTable: {
        loading: false,
        dataSource: [],
        // 表头
        ipagination: {
          current: 1,
          pageSize: 30,
          pageSizeOptions: ['10', '20', '30'],
          showTotal: (total, range) => {
            return range[0] + '-' + range[1] + ' 共' + total + '条'
          },
          showQuickJumper: true,
          showSizeChanger: true,
          total: 0,
        },
      },
      //确认记录列表数据
      recordTable: {
        loading: false,
        dataSource: [],
        // 表头
        ipagination: {
          current: 1,
          pageSize: 30,
          pageSizeOptions: ['10', '20', '30'],
          showTotal: (total, range) => {
            return range[0] + '-' + range[1] + ' 共' + total + '条'
          },
          showQuickJumper: true,
          showSizeChanger: true,
          total: 0,
        },
      },
      // 底部明细列表数据
      detailTable: {
        loading: false,
        dataSource: [],
        columns: [
          {
            title: '订单编号',
            key: 'orderCode',
            type: JVXETypes.normal,
            width: 120,
            defaultValue: '',
          },
          {
            title: '客户物料编码',
            key: 'customCode',
            type: JVXETypes.normal,
            width: 120,
            defaultValue: '',
          },
          {
            title: '物料编码',
            key: 'productCode',
            type: JVXETypes.normal,
            width: 120,
            defaultValue: '',
          },
          {
            title: '物料名称',
            key: 'productBatchNo',
            type: JVXETypes.normal,
            width: 300,
            defaultValue: '',
          },
          {
            title: '规格型号',
            key: 'materialSpec',
            dataIndex: 'materialSpec',
            type: JVXETypes.normal,
            width: 100,
          },
          {
            title: '配方号',
            key: 'formulaNumber',
            dataIndex: 'formulaNumber',
            width: 100,
            disabled: true,
          },
          {
            title: '生产锅',
            key: 'kettleId',
            dataIndex: 'kettleId',
            width: 180,
            type: JVXETypes.select,
            dictCode: 'tsl_md_kettle,kettle_name,kettle_no',
            disabled: true,
          },
          {
            title: '主数量',
            key: 'mainQuantity',
            dataIndex: 'mainQuantity',
            width: 120,
          },
          {
            title: '主单位',
            key: 'meUnit',
            dataIndex: 'meUnit',
            dictCode: 'ji_unit',
            type: JVXETypes.select,
            width: 100,
            disabled: true,
          },
          {
            title: '计划数量',
            key: 'planQuantity',
            dataIndex: 'planQuantity',
            width: 120,
          },
          {
            title: '完成数量',
            key: 'completedQuantity',
            dataIndex: 'completedQuantity',
            width: 120,
          },
          {
            title: '剩余数量',
            key: 'residualQuantity',
            dataIndex: 'residualQuantity',
            width: 120,
          },
          {
            title: '包装车间',
            key: 'packshopCode',
            type: JVXETypes.select,
            dictCode: 'sys_depart,depart_name,org_code,workshop_type=3 or workshop_type=4',
            width: 120,
            disabled: true,
          },
        ],
      },
      // 挂载状态标识
      isMounted: false,
      // 路由地址 0：前配，1：后配
      routePathType: '0',
      // 车间字典下拉
      dictOptions: [],
      settingColumns: [],
    }
  },
  created() {
    // 日期查询默认七天前
    this.aWeekTime()
    // 在created阶段初始化路由类型
    this.initRouteType(this.$route.path)
    // 获取车间字典，默认选择第一个
    this.loadworkshopDict()
  },
  mounted() {
    this.isMounted = true
    // 加载数据
    this.loadConfirmationRecordData()
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    },
  },
  watch: {
    // 监听路由变化
    $route(to) {
      this.handleRouteChange(to)
    },
    // 对车间选择的监听
    'queryParamConfirmation.workshopCode': {
      handler(newVal, oldVal) {
        // 当车间变化时自动触发查询
        if (newVal !== oldVal) {
          this.handleWorkshopChange()
        }
      },
      immediate: false,
    },
    // 对车间选择的监听
    'queryParamRecord.workshopCode': {
      handler(newVal, oldVal) {
        // 当车间变化时自动触发查询
        if (newVal !== oldVal) {
          this.handleWorkshopChange()
        }
      },
      immediate: false,
    },
  },
  methods: {
    // 日期查询默认七天前
    aWeekTime() {
      this.queryParamConfirmation.createTime_begin = getDate('day', -7)
      this.queryParamConfirmation.createTime_end = getDate('day', 0)
      this.queryParamRecord.createTime_begin = getDate('day', -7)
      this.queryParamRecord.createTime_end = getDate('day', 0)
    },
    // 加载车间字典 --> 默认选择第一条下拉数据
    loadworkshopDict() {
      getAction(`/sys/dict/getDictItems/erp_production_execution_organization,depart_name,depart_code`, {}).then(
        (res) => {
          if (res.success) {
            this.dictOptions = res.result.map((item) => ({ value: item.value, text: item.text }))
            if (this.dictOptions.length > 0 || this.dictOptions.length > 0) {
              this.queryParamConfirmation.workshopCode = this.dictOptions[0].value
              this.queryParamRecord.workshopCode = this.dictOptions[0].value
            }
          } else {
            this.dictOptions = []
          }
        }
      )
    },
    initDictConfig() {},
    // 修改查询方法
    searchQuery() {
      // 重置为第一页
      if (this.activeKey === '0') {
        this.confirmationTable.ipagination.current = 1
      } else {
        this.recordTable.ipagination.current = 1
      }
      // 调用查询
      this.loadConfirmationRecordData()
    },
    // 重置方法
    searchReset() {
      // 重置查询参数
      // 日期查询默认七天前
      this.aWeekTime()
      // 车间下拉默认选择第一个
      if (this.dictOptions.length > 0 || this.dictOptions.length > 0) {
        this.queryParamConfirmation.workshopCode = this.dictOptions[0].value
        this.queryParamRecord.workshopCode = this.dictOptions[0].value
      }
      // 重置为第一页
      if (this.activeKey === '0') {
        this.confirmationTable.ipagination.current = 1
      } else {
        this.recordTable.ipagination.current = 1
      }
      // 调用重置并刷新数据
      this.loadConfirmationRecordData()
    },
    // 路由类型初始化
    initRouteType(path) {
      const routeMap = {
        '/erp/manufactureconfirm/productionconfirmationbefore/ErpProductionProcessConfirmationBeforeList': '0',
        '/erp/manufactureconfirm/productionconfirmationafter/ErpProductionProcessConfirmationAfterList': '1',
      }
      this.routePathType = routeMap[path] || '0'
    },
    //路由切换
    handleRouteChange(to) {
      this.initRouteType(to.path)
      // 如果组件已挂载，重新加载数据
      if (this.isMounted) {
        // 重置查询
        this.searchReset()
      }
    },
    //根据路由选择不同，数据类型不同分别查询； routePathType：0：前配，1：后配；
    // 删除 返回
    // this.activeKey：0为生产过程确认，1为确认记录。
    loadConfirmationRecordData() {
      let urlList = this.url.planBeforeList
      let tableRef = this.activeKey === '0' ? 'confirmationTable' : 'recordTable'
      // 设置加载状态
      this[tableRef].loading = true
      //根据路由类型选择URL
      if (this.routePathType === '0') {
        //前配
        urlList = this.activeKey === '0' ? this.url.planBeforeList : this.url.beforeList
      } else if (this.routePathType === '1') {
        //后配
        urlList = this.activeKey === '0' ? this.url.planAfterList : this.url.afterList
      }
      // 获取当前表格的分页参数
      const pagination = this.activeKey === '0' ? this.confirmationTable.ipagination : this.recordTable.ipagination
      // 设置查询参数
      const queryParam = this.activeKey === '0' ? this.queryParamConfirmation : this.queryParamRecord
      const params = {
        ...queryParam,
        pageNo: pagination.current,
        pageSize: pagination.pageSize,
      }
      getAction(urlList, params)
        .then((res) => {
          if (res.success) {
            this[tableRef].dataSource = res.result.records || res.result || []
            if (res.result.total) {
              this[tableRef].ipagination.total = res.result.total
            } else {
              this[tableRef].ipagination.total = 0
            }
          } else {
            this.$message.warning(res.message)
          }
        })
        .finally(() => {
          this[tableRef].loading = false
        })
      this.confirmationSelectionRows = []
      this.confirmationSelectedRowKeys = []
    },
    handleChangeTab() {
      // 将底部明细列表置空
      this.detailTable.dataSource = []
      this.loadConfirmationRecordData()
    },
    // 修改：添加分页处理方法
    handleTableChange(pagination, filters, sorter, { currentDataSource }) {
      // 根据当前激活的标签页更新对应的分页参数
      if (this.activeKey === '0') {
        this.confirmationTable.ipagination = {
          ...this.confirmationTable.ipagination,
          current: pagination.current,
          pageSize: pagination.pageSize,
        }
      } else {
        this.recordTable.ipagination = {
          ...this.recordTable.ipagination,
          current: pagination.current,
          pageSize: pagination.pageSize,
        }
      }
      // 重新加载数据
      this.loadConfirmationRecordData()
    },
    handleAdd: function () {
      if (this.queryParamConfirmation.workshopCode === '' || this.queryParamConfirmation.workshopCode === null) {
        this.$message.warning('请选择生产车间')
        return
      }
      if (this.confirmationSelectionRows.length <= 0) {
        this.$message.warning('请选择生产过程')
        return
      }
      const confirmationData = {
        planId: this.confirmationSelectionRows[0].id,
        planCode: this.confirmationSelectionRows[0].code,
        workshopCode: this.queryParamConfirmation.workshopCode,
        //路由类型，0：前配/1：后配
        routePathType: this.routePathType,
      }
      // 点击添加时，获取当前查询框的车间值并传递给form
      this.$refs.modalForm.getWorkshopCode(confirmationData)
      this.$refs.modalForm.add()
      this.$refs.modalForm.title = '添加'
      this.$refs.modalForm.disableSubmit = false
    },
    // 修改modalFormOk方法
    modalFormOk() {
      // 将底部明细列表置空
      this.detailTable.dataSource = []
      // 添加成功后刷新列表
      this.loadConfirmationRecordData()
    },
    // 撤回
    handleWithdraw: function (record) {
      let that = this
      that.$confirm({
        title: '确认撤回',
        content: '是否撤回选中数据?',
        onOk: function () {
          that.withdrawRecord(record.id)
          that.onClearSelected()
        },
      })
    },
    async withdrawRecord(id) {
      try {
        let urlList = this.routePathType === '0' ? this.url.beforeWithdrawRecord : this.url.afterWithdrawRecord
        const res = await getAction(urlList, { id })
        if (res.success) {
          this.$message.success(res.result)
          this.loadConfirmationRecordData()
          // 将底部明细列表置空
          this.detailTable.dataSource = []
          return res.result
        } else {
          this.$message.warning(res.message)
          return ''
        }
      } catch (e) {
        return ''
      }
    },
    // 生产过程 选中时将所选数据的数据赋给confirmationSelectionRows
    onSelectChangeConfirmation(selectedRowKeys, selectionRows) {
      this.confirmationSelectedRowKeys = selectedRowKeys
      this.confirmationSelectionRows = selectionRows
      let params = {
        id: selectedRowKeys[0],
      }
      this.loadPlanDetailData(params)
    },
    rowSelectConfirmation(record, index) {
      return {
        on: {
          click: (event) => {
            let params = { id: record.id || '' }
            this.loadPlanDetailData(params)
          },
        },
      }
    },
    rowSelectRecord(record, index) {
      return {
        on: {
          click: (event) => {
            let params = { id: record.planId || '' }
            this.loadPlanDetailData(params)
          },
        },
      }
    },
    // 获取生产计划明细
    loadPlanDetailData(params) {
      this.detailTable.dataSource = []
      this.detailTable.loading = true
      getAction(this.url.tslProWorkshopPlanDetail, params)
        .then((res) => {
          if (res.success) {
            this.detailTable.dataSource = res.result
          } else {
            this.$message.warning(res.message)
          }
        })
        .finally(() => {
          this.detailTable.loading = false
        })
    },
    // 车间变化处理方法
    handleWorkshopChange() {
      // 将所选数据置空
      this.confirmationSelectedRowKeys = []
      this.confirmationSelectionRows = []
      // 将底部明细列表置空
      this.detailTable.dataSource = []
      // 重置当前标签页的分页到第一页
      if (this.activeKey === '0') {
        this.confirmationTable.ipagination.current = 1
      } else {
        this.recordTable.ipagination.current = 1
      }
      // 触发数据加载
      this.loadConfirmationRecordData()
    },
  },
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>
